# coding=UTF-8
'''
Created on 2018年12月11日

@author: lijie
'''
from utilites.database_helper import MysqlHelper

class DBFunction():
    def __init__(self,ev='test1',dbt='QA'):
        self.ev=ev
        self.dbt=dbt
        
    def get_T_COLLTASK_STATUS_flowID_by_tastname(self,tastname):
        sql="select FLOW_ID from T_COLLTASK_STATUS where TASK_NAME='"+tastname+"'"
        fid=MysqlHelper(self.ev,self.dbt).sqlquery(sql)[0]
        return fid[0]
    
    def get_T_DATASOURCE_flowID_by_dsname(self,dsname):
        sql="select FLOW_ID from T_DATASOURCE where DATASOURCE_NAME='"+dsname+"'"
        fid=MysqlHelper(self.ev,self.dbt).sqlquery(sql)[0]
        return fid['FLOW_ID']
    
    def get_T_DATALAYER_flowID_by_lyname(self,lyname):
        sql="select FLOW_ID from T_DATALAYER where LAYER_NAME='"+lyname+"'"
        fid=MysqlHelper(self.ev,self.dbt).sqlquery(sql)[0]
        return fid['FLOW_ID']
    
    def get_T_DATALAYER_info_by_id(self,fid):
        sql="select * from T_DATALAYER where FLOW_ID='"+fid+"'"
        info=MysqlHelper(self.ev,self.dbt).sqlquery(sql)[0]
        return info
    
    def get_T_DATALAYER_TREE_PARENT_FLOW_ID_by_id(self,fid):
        sql="select PARENT_FLOW_ID from T_DATALAYER_TREE where LAYER_FLOW_ID='"+fid+"'"
        pfid=MysqlHelper(self.ev,self.dbt).sqlquery(sql)[0]
        return pfid
    
    def get_T_MODEL_INFO_by_name(self,m_name):
        sql="select * from T_MODEL_INFO where MODEL_NAME='"+m_name+"'"
        infos=MysqlHelper(self.ev,self.dbt).sqlquery(sql)[0]
        return infos
    
    def get_T_BUSINESS_TYPE_by_name(self,m_name):
        sql="select * from T_BUSINESS_TYPE where MODEL_ID IN (select FLOW_ID from T_MODEL_INFO where MODEL_NAME='"+m_name+"')"
        infos=MysqlHelper(self.ev,self.dbt).sqlquery(sql)[0]
        return infos
    
    def get_T_DATASET_by_name(self,ds_name):
        sql="select * from T_DATASET where name='"+ds_name+"' "
        infos=MysqlHelper(self.ev,self.dbt).sqlquery(sql)[0]
        return infos